package com.luckdraw.domain;

import java.util.Date;

import org.nutz.dao.entity.annotation.ColDefine;
import org.nutz.dao.entity.annotation.ColType;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.PK;
import org.nutz.dao.entity.annotation.Table;
import org.nutz.lang.Strings;
import org.nutz.repo.Base64;

@Table("LuckDraw_User")
@PK(name="PK_LUCKDRAW_USER_UID_APPID",value={"userId","wxAppId"})
public class User {

	/**
	 * 用户ID
	 */
	@Column("user_id")
	@ColDefine(type=ColType.VARCHAR,notNull=true,width=36)
	private String userId;
	
	/**
	 * 微信appId
	 */
	@Column("wx_app_id")
	@ColDefine(type=ColType.VARCHAR,width=36)
	private String wxAppId;
	
	/**
	 * 推广人UserId
	 */
	@Column("agent_user_id")
	@ColDefine(type=ColType.VARCHAR,width=36)
	private String agentUserId;

	/**
	 * 用户昵称
	 */
	@Column("nick_name")
	@ColDefine(type=ColType.VARCHAR,width=36)
	private String nickName;

	/**
	 * 账户余额
	 */
	@Column("amount")
	@ColDefine(width=10,precision=0)
	private int amount;
	
	/**
	 * 注册时间
	 */
	@Column("register_time")
	private Date registerTime;

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getAgentUserId() {
		return agentUserId;
	}

	public void setAgentUserId(String agentUserId) {
		this.agentUserId = agentUserId;
	}

	public String getNickName() {
		return nickName;
	}
	
	/**
	 * 解决编码不一致导致乱码问题<br>
	 * 将数据使用Base64解码后显示<br>
	 * 若要获取实际数据时使用本方法
	 * @return
	 */
	public String getNickName2(){
		if(Strings.isNotBlank(this.nickName)){
			return new String(Base64.decode(nickName));
		}else{
			return this.nickName;
		}
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	/**
	 * 解决编码不一致导致乱码问题<br>
	 * 将数据使用Base64编码后存储
	 * @param nickName
	 */
	public void setNickName2(String nickName) {
		if(Strings.isNotBlank(nickName)){
			this.nickName = Base64.encodeToString(nickName.getBytes(),false);
		}else{
			this.nickName = "";
		}
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	public String getWxAppId() {
		return wxAppId;
	}

	public void setWxAppId(String wxAppId) {
		this.wxAppId = wxAppId;
	}

	public Date getRegisterTime() {
		return registerTime;
	}

	public void setRegisterTime(Date registerTime) {
		this.registerTime = registerTime;
	}
	
}
